
insheet using HWCMasterData_Clean_201229.csv

********** Treatment Key *****************************
*******************************	Type 1 ****	Type 2 ***
** treatment == 1 - HOM			R=50, W=42	R=50, W=42
** treatment == 2 - HET WEALTH	R=50, W=36	R=50, W=48
** treatment == 3 - HET RISK	R=30, W=42	R=70, W=42
** treatment == 4 - HET BAL		R=30, W=36	R=70, W=48
** treatment == 5 - HET UNBAL	R=70, W=36	R=30, W=48
******************************************************


********** Variable Generation ***********************
drop if period==16 //Period 16 does not include behavioral data but allowed for payment calculation in experimental program
gen groupid = (treatment*1000)+(session*10)+group
gen subjectid = (groupid*10)+subjectnum

gen ni = real(investment)
gen ni100 = ni*100

** High/low risk/endowment dummies
gen en_lo = 0
replace en_lo = 1 if endowment==36
gen en_hi = 0
replace en_hi = 1 if endowment==48

gen ri_lo = 0
replace ri_lo = 1 if risk==30
gen ri_hi = 0
replace ri_hi = 1 if risk==70

** Risk/endowment interaction dummies
gen ri_lo_en_lo = 0
replace ri_lo_en_lo = 1 if ri_lo==1 & en_lo==1
gen ri_lo_en_hi = 0
replace ri_lo_en_hi = 1 if ri_lo==1 & en_hi==1

gen ri_hi_en_lo = 0
replace ri_hi_en_lo = 1 if ri_hi==1 & en_lo==1
gen ri_hi_en_hi = 0
replace ri_hi_en_hi = 1 if ri_hi==1 & en_hi==1

** Dummy for full group cooperation
gen groupsuccess=0
replace groupsuccess=1 if groupinvestment==4

** Individual risk measures
gen totalrisk = riskchoice1 + riskchoice2 + riskchoice3 + riskchoice4 + riskchoice5 + riskchoice6 + riskchoice7 + riskchoice8 + riskchoice9 + riskchoice10
by groupid, sort: egen av_tot_risk = mean(totalrisk)
by groupid period, sort: egen av_loss = mean(loss)
gen otherinvest = groupinvestment - ni

** Single group sessions dummies
gen singlesess = 0
replace singlesess = 1 if session==8 | session==13 | session==14 | session==15 | session==17


******************************************************
********** Analysis **********************************
******************************************************

********** FIGURES ***********************************
********** Figure 1A Mean # of subjects contributing per group
preserve
collapse groupinvestment, by(treatment)
graph bar groupinvestment, over(treatment) blabel(total, format(%9.2f)) ylabel(0(1)4) play(HWC_2)
graph save AvGroupCoop_ByTreatment_paper.gph, replace
restore

********** Figure 1B Mean rate of coop. of individuals by type
preserve
replace type=1 if treatment==1
collapse ni100, by(treatment type)
graph bar ni100, over(type) over(treatment) blabel(total, format(%9.2f)) ylabel(0(20)100) play(HWC_1)
graph save AvIndCoop_ByType.gph, replace
restore


********** TABLES ************************************
********** Group Analysis
preserve
keep if subjectnum==1
xtset groupid period

********** Pooled logit and Brant test 
ologit groupinvestment i.treatment, vce(cluster groupid) or
brant, detail

********** Table 2: Models 1-4 
eststo clear
eststo: xtologit groupinvestment i.treatment, vce(cluster groupid) or
eststo: xtlogit groupsuccess i.treatment, vce(cluster groupid) or
eststo: xtlogit groupsuccess i.treatment period l.groupinvestment, vce(cluster groupid) or
eststo: xtlogit groupsuccess i.treatment l.groupinvestment av_tot_risk singlesess period, vce(cluster groupid) or
esttab, p scalars(chi2) star(* 0.10 ** 0.05 *** 0.01) brackets label eform

//Testing for treatment effects:
test i2.treatment = i3.treatment
test i2.treatment = i4.treatment
test i2.treatment = i5.treatment

test i3.treatment = i4.treatment
test i3.treatment = i5.treatment

test i4.treatment = i5.treatment

restore


********** Individual Analysis
preserve
xtset subjectid period

********** Table 3 
********** Models 5-7 
eststo clear
eststo: xtlogit ni ri_lo ri_hi en_lo en_hi, vce(cluster groupid) or
eststo: xtlogit ni ri_lo ri_hi en_lo en_hi ri_lo_en_lo ri_lo_en_hi ri_hi_en_lo ri_hi_en_hi, vce(cluster groupid) or
eststo: xtlogit ni ri_lo ri_hi en_lo en_hi ri_lo_en_lo ri_lo_en_hi ri_hi_en_lo ri_hi_en_hi l.ni l.loss l.otherinvest totalrisk singlesess period, vce(cluster groupid) or
esttab, p scalars(chi2) star(* 0.10 ** 0.05 *** 0.01) brackets label eform

restore

********** Models 8&9 Regression using only two-dimension het (i.e., HET BAL and HET UNBAL) treatments
preserve
keep if treatment>3
xtset subjectid period

eststo clear
eststo: xtlogit ni ri_lo_en_lo ri_lo_en_hi ri_hi_en_lo, vce(cluster groupid) or
eststo: xtlogit ni ri_lo_en_lo ri_lo_en_hi ri_hi_en_lo l.ni l.loss l.otherinvest totalrisk singlesess period, vce(cluster groupid) or

esttab, p scalars(chi2) star(* 0.10 ** 0.05 *** 0.01) brackets label eform
test ri_lo_en_lo == ri_lo_en_hi

restore



********** APPENDIX **********************************
*****************Figure A1****************************
preserve
keep if subjectnum==1
twoway histogram groupinvestment, ylabel(0(10)50) xlabel(0(1)4) discrete percent by(treatment) 
restore

